import QueryMaterial2 from "@/components/QueryMaterial2";
import { s_getSelectData, s_getStockInfo, s_operateInfo, s_stockIn, s_stockOut, status2text } from "@/services/basis";
import { ActionType, EditableFormInstance, EditableProTable, ProCard, ProColumns, ProForm, ProFormDatePicker, ProFormDateRangePicker, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea, ProTable } from "@ant-design/pro-components";
import { Button ,Col,Divider,Image, message, Modal, Row, Space, Tag} from "antd";
import moment from "moment";
import { useEffect, useRef, useState } from "react";
import { useModel } from "@umijs/max";

const App:React.FC=()=>{
    const [tdata,setTdata]=useState<any[]>([]);
    const [selectedRecords,setSelectedRecords]=useState<any[]>([]);

    const actionRef_m=useRef<ActionType>();
    //新增
    const [etype,setEtype]=useState(1);//0编辑领料单，1新增领料单，2出库--控制实际出库列+删除列是否显示
    const [open,setOpen]=useState(false);
    const formRef_main=useRef<ProFormInstance>();
    const editableRef_main=useRef<EditableFormInstance>();
    const actionRef_main=useRef<ActionType>();

    //查询
    const [openQuery,setOpenQuery]=useState(false);
    const [selectedRecords3,setSelectedRecords3]=useState<any[]>([]);
    const [tdata3,setTdata3]=useState<any[]>([]);
    const formRef_query=useRef<ProFormInstance>();
    const editableRef_query=useRef<EditableFormInstance>();
    const actionRef_query=useRef<ActionType>();

    const [material,setMaterial]=useState([]);
    const [dataSource,setDataSource]=useState([]);

    //领料单出库的标记
    const [openStockOut,setOpenStockOut]=useState(false);
    const formRef_stockout=useRef<ProFormInstance>();
    const actionRef_stockout=useRef<ActionType>();
    const editableRef_stockout=useRef<EditableFormInstance>();
    const [total,setTotal]=useState(0);

    const [selectedLineKeys,setSelectedLineKeys]=useState<any[]>([]);    
    const { initialState, setInitialState } = useModel('@@initialState');

    //当组件选择物料时，更新表格并重载--
                useEffect(()=>{
                   if(material.length>0){
                   var x:any[]=editableRef_main.current?.getRowsData?.();
                   // alert(JSON.stringify(x));
                   if(x==undefined)
                      x=[];
                   material.map((item:any)=>{
                      x?.push({rid:Math.random().toFixed(10),id:Math.random().toFixed(10).toString(),
                                material_id:item.id,code:item.code,name:item.name,
                                invstd:item.invstd,invstd2:item.invstd2,munit_name:item.munit_name,  
                                quantity:1,
                                userdefine_id:'[]',vendor_id:'[]',pic:item.pic,
                      });
                   });
                   // alert(JSON.stringify(x));
                   setDataSource(x);
                    
                   formRef_main.current?.setFieldValue('editable_main',x);
                   actionRef_main.current?.reloadAndRest?.();
                }
                },[material]);
    
    interface DataType{
//         rid,id,x_id,source_type,out_type_id,operate_time,operater_id,memo,vouch_code,status,org_id,warehouse_id,
// outtype_name,operater_name,org_name,warehouse_name
   rid?:number,id?:number,x_id?:number,source_type?:number,out_type_id?:number,operate_time?:string,operater_id?:number,
   memo?:string,vouch_code?:string,status?:number,org_id?:number,warehouse_id?:number,
   outtype_name?:string,operater_name?:string,org_name?:string,warehouse_name?:string,
   workcenter_id?:number,workgroup_id?:number,workcenter_name?:string,workgroup_name?:string,
     };

    const columns:ProColumns<DataType>[]=[
        {dataIndex:'rid',title:'rid',search:false},{dataIndex:'id',title:'id',search:false},
        {dataIndex:'warehouse_name',title:'仓库',search:false}, 
        {dataIndex:'vouch_code',title:'领料单号',width:100},
        {dataIndex:'source_type',title:'来源',search:false,
            render:(text)=>text==0?'自制':'委外领料',
        },
        {dataIndex:'outtype_name',title:'出库类别',search:false},
        {dataIndex:'org_name',title:'部门',search:false}, 
        {dataIndex:'workcenter_name',title:'委外中心',width:100},
        {dataIndex:'workgroup_name',title:'委外商',width:100},
        {dataIndex:'operate_time',title:'制单时间',valueType:'date',width:100},
        {dataIndex:'operater_name',title:'制单人',search:false},
        {dataIndex:'memo',title:'备注',search:false},

        {dataIndex:'status',title:'状态',valueType:'select',width:80,
            valueEnum:{1:{text:'未审核'},5:{text:'已审核'},
            6:{text:'已弃审'},2:{text:'关闭'},3:{text:'删除'},9:{text:'全部'}}
        }, 
        // 
    ];

    interface DataType2{
        // rid,id,mid,source_type,source_produce_order_mid,source_produce_order_did,
        // source_taskcard_id,warehouse_id,quantity,quantity_outed,material_id,
        // userdefine_id,userdefine_name,memo,
        // produce_vouch_code,warehouse_name,
        // code,name,invstd,invstd2,pic,munit_name
        rid?:number,id?:number,mid?:number,source_type?:number,source_produce_order_mid?:number,
        source_produce_order_did?:number,
        source_taskcard_id?:number,warehouse_id?:number,quantity?:number,quantity_outed?:number,material_id?:number,
        userdefine_id?:string,userdefine_name?:string,memo?:string,
        produce_vouch_code?:string,warehouse_name?:string,quantity_out?:number,
        code?:string,name?:string,invstd?:string,invstd2?:string,pic?:string,munit_name?:string
     };

    const columns2:ProColumns<DataType2>[]=[
        {dataIndex:'pic',title:'图片' ,editable:false,
        //     render:(text)=>{
        //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
        //         return <Image src={pic}  
        //                style={{width:100,height:100}} alt='无' />
        //    },
        //  },
          render:(text,record,index,k)=>{
                       var pic="/basis_api/file/get2?filename="+record.code;
                       return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
          },
        },
         {dataIndex:'rid',title:'rid',editable:false,},
         {dataIndex:'mid',title:'mid',editable:false,},{dataIndex:'id',title:'ID',editable:false,},
         {dataIndex:'produce_vouch_code',title:'备料单号',editable:false,},
         {dataIndex:'material_id',title:'物料ID',editable:false,},
        {dataIndex:'code',title:'SKU',editable:false,},{dataIndex:'name',title:'名称',editable:false,},
        {dataIndex:'invstd',title:'包装规格',editable:false,},
        {dataIndex:'invstd2',title:'型号',editable:false,}, 
        // {dataIndex:'userdefine_id',title:'自定义ID'},{dataIndex:'userdefine_name',title:'自定义值'},
        {dataIndex:'munit_name',title:'单位',editable:false,},
        {dataIndex:'quantity',title:'申领数量',width:120,editable:etype==2?false:undefined,
            render:(text:any)=>text>=0?<Tag style={{width:80}}>{text}</Tag>:<Tag color="red" style={{width:80}}>{text}</Tag>,
        }, 
        {dataIndex:'quantity_outed',title:'已出库数量',editable:false},
        {dataIndex:'quantity_out',title:'本次出库数量',
            hidden:etype==2?false:true,
            // render:(text,record,index)=>(record.quantity?record.quantity:0)-(record.quantity_outed?record.quantity_outed:0),
        },
        {dataIndex:'memo',title:'备注'}, 
        {
            title:'操作',            
            fixed:'right',
            valueType:'option',
            width:80,
            editable:false,
            render:(text,record,_,action)=>[
               <a  key='del2'
                   onClick={()=>{
                     if(etype==2){
                        var x:any[]=editableRef_stockout.current?.getRowsData?.();
                        formRef_stockout.current?.setFieldValue('editable_stockout',x.filter((item)=>item.rid!=record.rid));
                     }else{
                       var x:any[]=editableRef_main.current?.getRowsData?.();
                       formRef_main.current?.setFieldValue('editable_main',x.filter((item)=>item.rid!=record.rid));
                     }
                   }}
               >
                   删除
               </a>,
            ]
         }
    ];

    //从采购订单生单的界面数据
    interface DataType3{
//         rid,id,x_id,vouch_code,vendor_id,status,memo,operate_time,
//  did,material_id,userdefine_id,userdefine_name,quantity,deliverdate,source_type,source_mid,source_did,
//  quantity_deliver,quantity_reback,quantity_stockin,quantity_undeliver,
//  code,name,invstd,invstd2,munit_name,pic,
//  vendor_name,quantity_in_now
rid?:number,id?:number,x_id?:number,vouch_code?:string,vendor_id?:number,status?:number,memo?:string,
operate_time?:string,
 did?:number,material_id?:number,userdefine_id?:string,userdefine_name?:string,quantity?:number,
 deliverdate?:string,source_type?:string,source_mid?:number,source_did?:number,
 quantity_deliver?:number,quantity_reback?:number,quantity_stockin?:number,quantity_undeliver?:number,
 code?:string,name?:string,invstd?:string,invstd2?:string,munit_name?:string,pic?:string,
 vendor_name?:string,quantity_in_now?:number
    };

    const columns3:ProColumns<DataType3>[]=[
        {dataIndex:'pic',title:'图片' ,editable:false,
        //     render:(text)=>{
        //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
        //         return <Image src={pic}  
        //                style={{width:100,height:100}} alt='无' />
        //    },
        //  },
          render:(text,record,index,k)=>{
                       var pic="/basis_api/file/get2?filename="+record.code;
                       return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
          },
        },
       {dataIndex:'rid',title:'rid',editable:false},{dataIndex:'did',title:'did',editable:false},
       {dataIndex:'vendor_id',title:'供应商ID',editable:false,},{dataIndex:'vendor_name',title:'供应商',editable:false},
       {dataIndex:'vouch_code',title:'采购单号',editable:false},{dataIndex:'material_id',title:'物料ID',editable:false},
       {dataIndex:'code',title:'SKU',editable:false},{dataIndex:'name',title:'名称',editable:false},
       {dataIndex:'invstd',title:'包装规格',editable:false},{dataIndex:'invstd2',title:'型号',editable:false},
       {dataIndex:'munit_name',title:'单位',editable:false},
       {dataIndex:'quantity',title:'总数量',editable:false},
       {dataIndex:'deliverdate',title:'预计交货日期',editable:false,valueType:'date'},
       {dataIndex:'quantity_deliver',title:'已交货数',editable:false},{dataIndex:'quantity_reback',title:'退货数',editable:false},
       {dataIndex:'quantity_undeliver',title:'未交货数',editable:false}, 
       {dataIndex:'quantity_in_now',title:'本次入库数',width:120,valueType:'digit' },
       {dataIndex:'operate_time',title:'下单日期',editable:false,valueType:'date'},
    //    {dataIndex:'status',title:'状态',editable:false},
    ];

     //  操作询价单/关闭/删除/恢复
           async function operateInfo(n:number){
            // source,x_id,operater_id,otype,id
            if(selectedRecords.length==0)
               message.warning('请选择要操作的行');
            else if(n==5&&selectedRecords[0].status==5)
                        message.warning('此单据已审核，请不要重复操作');
             else if(n==6&&selectedRecords[0].status!=5)
                        message.warning('此单据未审核，不能弃审');
            else{
             const x=await s_operateInfo({x_id:1,source:'stock_out_apply_main',
                   operater_id:initialState?.currentUser?.userid,
                         otype:n,id:selectedRecords[0].id});
             if(x.success){
               message.success('操作成功');
               actionRef_m.current?.reloadAndRest?.();
             }else
               message.error('操作错误，请联系管理员。');
            }
         }

    // 打开领料单编辑窗口- --1新增，0编辑
    function openMain(type:number){
       setEtype(type);
       setOpen(true);
    };

    //退出领料单编辑窗口
    function exitMain(){
        setOpen(false);
    };

    //保存领料单
    async function saveMain(){
         const fdata2=formRef_main.current?.getFieldsValue();
        //  alert(JSON.stringify(fdata2));   
        //表头数据
         const fdata={
                    //    vendor_id:fdata2.vendor_id,
                      warehouse_id:fdata2.warehouse_id,
                      stockin_time:moment(moment(fdata2.stockin_time).toDate()).format('YYYY-MM-DD HH:mm:ss'),
                      memo:fdata2.memo,
                      id:fdata2.id,
                      out_type_id:fdata2.out_type_id,
                      source_type:fdata2.source_type,
                      workcenter_id:fdata2.workcenter_id,
                      workgroup_id:fdata2.workgroup_id,
                      org_id:fdata2.org_id,
                      alloc_type:3,
         };
         //表体数据
        //   alert(JSON.stringify(fdata2.editable_main));
         const tdata=fdata2.editable_main.map((item:any)=>({
               material_id:item.material_id,
               userdefine_id:item.userdefine_id,
               userdefine_name:item.userdefine_name,
               quantity:item.quantity,
               source_type:0,
            //    source_order_mid:item.source_order_mid,
            //    source_order_did:item.source_order_did,
               id:item.id,
               mid:item.mid,
               memo:item.memo,
               
           }));
        //    alert(JSON.stringify(fdata));
        //   alert(JSON.stringify(tdata));
        // x_id,operater_id,etype,source,tdata
        const x=await s_stockOut({x_id:1,operater_id:initialState?.currentUser?.userid,etype,
                                 source:'stock_out_apply',tdata:{fdata,tdata}});
        if(x.success){
            message.success('保存成功');
            setEtype(0);
            actionRef_m.current?.reloadAndRest?.();
            // alert(JSON.stringify(x.data[0][0]));
            //修改当前的表单界面值
            formRef_main.current?.setFieldsValue({
                vouch_code:x.data[0][0].vouch_code,
                id:x.data[0][0].id,
                editable_main:x.data[1],

            });
        }else
          message.warning('保存失败，请联系管理员');
    };

//编辑领料单
function editStockIn(){
    const fdata=editableRef_main.current?.getRowsData?.();
    fdata?.map((item:any)=>{
        actionRef_main.current?.startEditable(item.rid);
    });

};


    //备料出库调用按钮
    function stockOut(){
        // alert('执行出库，显示出库界面,与编辑界面多出实际出库数量这一栏');
       setEtype(2); 
       setOpenStockOut(true);
    };

    //退出出库界面
    function exitStockOut(){
        setOpenStockOut(false);
    }

    //编辑出库数据
    function editStockOut(){
        const fdata=editableRef_stockout.current?.getRowsData?.();
        fdata?.map((item:any)=>{
            actionRef_stockout.current?.startEditable(item.rid);
        });
    }

    //保存为材料出库单
    async function saveStockOut(){
        // alert('ddd00');
        const fdata2=formRef_stockout.current?.getFieldsValue();
       //  alert(JSON.stringify(fdata2));   
       if( !(fdata2.stockout_vouch_code==undefined||fdata2.stockout_vouch_code=='') )
          message.warning('不可以重复出库。请重新打开领料单再试');
        else{
       //表头数据
        const fdata={
                   //    vendor_id:fdata2.vendor_id,
                     warehouse_id:fdata2.warehouse_id,
                     memo:fdata2.memo,
                     id:fdata2.id,
                     outtype_id:fdata2.outtype_id,
                     org_id:fdata2.org_id,
                     workcenter_id:fdata2.workcenter_id,
                     workgroup_id:fdata2.workgroup_id,
                     dotype:2,
                    //  etype:fdata2.stockout_vouch_code&&fdata2.stockout_vouch_code!=''?0:1,
                     source_type:fdata2.source_type,
                     stockout_time:fdata2.stockout_time?moment(moment(fdata2.stockout_time).toDate()).format('YYYY-MM-DD HH:mm:ss'):null,
        };
        //表体数据
       //   alert(JSON.stringify(fdata2.editable_main));
    //    alert(JSON.stringify(fdata));
        const tdata=fdata2.editable_stockout.map((item:any)=>({
              material_id:item.material_id,
              userdefine_id:item.userdefine_id,
              userdefine_name:item.userdefine_name,
              quantity:item.quantity_out,
            //   qauntity_out:item.quantity_out,
              source_type:1,
              source_order_mid:item.mid,
              source_order_did:item.id,
            //   id:item.id,
            //   mid:item.mid,
              memo:item.memo,
          }));
           
        //    alert(JSON.stringify(tdata));
       // x_id,operater_id,etype,source,tdata

       const x=await s_stockOut({x_id:1,operater_id:initialState?.currentUser?.userid ,etype:1,
                                source:'stock_out_produce',tdata:{fdata,tdata}});

    //    alert(JSON.stringify(x));                         
       if(x.success){
           message.success('保存成功');
        //    setEtype(0);
           actionRef_m.current?.reloadAndRest?.();
           //修改当前的表单界面值
           formRef_stockout.current?.setFieldsValue({
               stockout_vouch_code:x.data[0][0].vouch_code,
               stockout_id:x.data[0][0].id,
               editable_main:x.data[1],
           });
       }else
         message.warning('保存失败，请联系管理员');
      };
   };

//   ===================================================================================================
    return <>
         <ProCard title='外发拣货列表' style={{height:450,overflow:'auto'}}
             extra={<Space>
                {/* <Button>查询</Button> */}
                <Button onClick={()=>openMain(1)}>新增外发单</Button>
                {/* <Button onClick={()=>openMain(0)}>编辑出库单</Button> */}
                <Button onClick={()=>stockOut()}>完成拣货</Button>
                {/* <Button onClick={()=>operateInfo(5)}>审核出库</Button>
                <Button onClick={()=>operateInfo(6)}>取消审核</Button> */}
                <Button onClick={()=>operateInfo(2)}>关闭</Button>
                <Button onClick={()=>operateInfo(3)}>删除</Button>
                <Button onClick={()=>operateInfo(1)}>恢复</Button>
             </Space>}
         >
              <ProTable<DataType>
                  actionRef={actionRef_m}
                  search={{span:4}}
                  options={false}
                  columns={columns}
                  rowKey='id'
                  request={async (param)=>{
                    const x=await s_getStockInfo({source:'v_stock_out_apply_main',x_id:1,
                                   fdata:{id:0,alloc_type:3,param}});
                    setTotal(x.data[0][0].count);
                    return{
                        data:x.data[1],
                        success:true,
                    }
                  }}
                  rowSelection={{
                    type:'radio',
                    selectedRowKeys:selectedLineKeys,
                    async  onChange(selectedRowKeys, selectedRows, info) {
                        setSelectedRecords(selectedRows);
                        setSelectedLineKeys(selectedRowKeys);
                        //刷新子表明细
                        const x=await s_getStockInfo({source:'v_stock_out_apply_detail',x_id:1,
                                   fdata:{mid:selectedRowKeys.length>0?selectedRowKeys[0]:0}});
                        setTdata(x.data[0])
                    },
                  }}
                  onRow={(record)=>{
                     return {
                        onClick:async ()=>{
                            const k=record.id;
                            setSelectedRecords([record]);
                            setSelectedLineKeys([k]);
                          //刷新子表明细
                            const x=await s_getStockInfo({source:'v_stock_out_apply_detail',x_id:1,
                                   fdata:{mid:k&&k!=0?k:0}});
                            setTdata(x.data[0])
                      },
                   }
                  }}
                  scroll={{y:'20vh'}}
                  pagination={{
                    showQuickJumper:true,
                    showSizeChanger:true,
                    defaultPageSize:5,
                    defaultCurrent:1,
                    total,
                  }}
                />
         </ProCard>
         {/* 入库单明细表---------- */}
         <ProCard style={{height:300,overflow:'auto'}}>
         <ProTable<DataType2>
                  search={false}
                  options={false}
                  columns={columns2}
                  rowKey='id'
                  dataSource={tdata}
                />
        </ProCard>

        {/* 领料单的新增/编辑主界面---------------------------------------------------------------- */}
        <Modal open={open} width='90%' style={{top:10}} okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
               closable destroyOnClose onCancel={()=>exitMain()} onClose={()=>exitMain()}>
           <ProCard title={etype==1?'新增外发库':'编辑外发库'} style={{height:900,overflow:'auto'}}
                extra={<Space>
                    <QueryMaterial2 setData={setMaterial} type='checkbox' x_id={1}/>
                    <Button onClick={()=>editStockIn()}>编辑外发单</Button>
                    <Button onClick={()=>formRef_main.current?.submit()}>保存外发单</Button>
                    <Button onClick={()=>exitMain()}>退出</Button>
                </Space>}>
                <ProForm formRef={formRef_main} layout="horizontal" labelAlign="left" labelCol={{offset:0,span:6}}
                    labelWrap submitter={false} onFinish={()=>saveMain()}
                    initialValues={etype==0?{
                                  ...selectedRecords[0],
                                  editable_main:tdata,
                               }
                             :{source_type:1}}
                    >
                        
                     <Row gutter={8}>
                         <Col span={4}>
                            
                           <ProFormText name='id' label='id'  />
                            <ProFormText name='vouch_code' label='领料单号' width={200} />
                         </Col>
                         
                         <Col span={4}>
                           <ProFormSelect name='warehouse_id' label='仓库' width={200} 
                           rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'base2_ware'});
                                      return x.data;}}
                                />
                         </Col>
                          
                     <Col span={4}>
                            {/* <ProFormText name='intype_id' label='XXX'/> */}
                            <ProFormSelect name='out_type_id' label='领料类型' width={200} 
                        //    rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'base_outtype'});
                                      return x.data;}}
                                />
                             
                         </Col>
                         <Col span={4}>
                            <ProFormText name='memo' label='备注' width={500}/>
                         </Col>
                   </Row>
                    <Row gutter={8}>
                        <Col span={4}>
                        <ProFormSelect name='workcenter_id' label='工作中心' width={200} 
                        //    rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'workcenter'});
                                      return x.data;}}
                                />
                        </Col>
                        <Col span={4}>
                        <ProFormSelect name='workgroup_id' label='委外商' width={200} 
                        //    rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'workgroup'});
                                      return x.data;}}
                                />
                        </Col>
                        <Col span={4}>
                        <ProFormSelect name='org_id' label='部门' width={200} 
                        //    rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'base_organization'});
                                      return x.data;}}
                                />
                        </Col>
                        <Col span={4}>
                        <ProFormRadio.Group name='source_type' label='类别' 
                                 options={[{value:1,label:'蓝字'},{value:-1,label:'红字',style:{color:'red'}}]}
                              />
                        </Col>
                    </Row> 

                     <EditableProTable<DataType2>
                        name='editable_main'
                        rowKey='rid'
                        columns={columns2}
                        actionRef={actionRef_main}
                        editableFormRef={editableRef_main}
                        editable={{
                            type:'multiple',
                        }}
                        recordCreatorProps={false}
                        search={false}
                        options={false}
                        />
                </ProForm>
           </ProCard>
        </Modal>
        
         {/* 出库界面--------------------------------------------------------------- */}
         <Modal open={openStockOut} width='90%' style={{top:10}} okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
               closable destroyOnClose onCancel={()=>exitStockOut()} onClose={()=>exitStockOut()}>
           <ProCard title= '新增出库'  style={{height:900,overflow:'auto'}}
                extra={<Space>
                    {/* <QueryMaterial2 setData={setMaterial} type='checkbox' x_id={1}/> */}
                    <Button onClick={()=>editStockOut()}>编辑数量</Button>
                    <Button onClick={()=>formRef_stockout.current?.submit()}>保存出库</Button>
                    <Button onClick={()=>exitStockOut()}>退出</Button>
                </Space>}>
                <ProForm formRef={formRef_stockout} layout="horizontal" labelAlign="left" labelCol={{offset:0,span:6}}
                    labelWrap submitter={false} onFinish={()=>saveStockOut()}
                    initialValues={etype==2?{
                                  ...selectedRecords[0],
                                  editable_stockout:tdata,
                                  stockout_time:moment(),
                                  source_type:1,
                               }
                             :{}}
                    >
                        
                     <Row gutter={8}>
                         <Col span={4}>
                           <ProFormText name='id' label='id' hidden={true} />
                            <ProFormText name='vouch_code' label='领料单号' width={200} />
                            <ProFormSelect name='org_id' label='领料部门' width={200}
                              showSearch
                              request={async ()=>{
                                  const x=await s_getSelectData({x_id:1,source:'base_organization'});
                                    return x.data;}}
                            />
                         </Col>
                         
                         <Col span={4}>
                           <ProFormSelect name='warehouse_id' label='仓库' width={200} 
                           rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'base2_ware'});
                                      return x.data;}}
                                />
                             <ProFormSelect name='workcenter_id' label='工作中心' width={200} 
                           rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'workcenter'});
                                      return x.data;}}
                                />    
                         </Col>
                          
                     <Col span={4}>
                            {/* <ProFormText name='intype_id' label='XXX'/> */}
                            <ProFormSelect name='outtype_id' label='出库类型' width={200} 
                        //    rules={[{required:true,message:'必填项'}]}
                               showSearch
                               request={async ()=>{
                                    const x=await s_getSelectData({x_id:1,source:'base_outtype'});
                                      return x.data;}}
                                />
                                 <ProFormSelect name='workgroup_id' label='委外商' width={200} 
                                    rules={[{required:true,message:'必填项'}]}
                                   showSearch
                                   request={async ()=>{
                                       const x=await s_getSelectData({x_id:1,source:'workgroup'});
                                          return x.data;}}
                                />  
                             
                         </Col>

                         <Col span={4}>
                            
                         <ProFormRadio.Group name='source_type' label='类别' 
                                 options={[{value:1,label:'蓝字'},{value:-1,label:'红字',style:{color:'red'}}]}
                              />
                          <ProFormText name='stockout_vouch_code' label='出库单号'/>
                         </Col>
                         <Col span={4}>
                            <ProFormDatePicker name='stockout_time' label='出库日期' width={200}/>
                            <ProFormText name='memo' label='备注' width={500}/>
                         </Col>
                   </Row>
                     

                     <EditableProTable<DataType2>
                        name='editable_stockout'
                        rowKey='rid'
                        columns={columns2}
                        actionRef={actionRef_stockout}
                        editableFormRef={editableRef_stockout}
                        editable={{
                            type:'multiple',
                        }}
                        recordCreatorProps={false}
                        search={false}
                        options={false}
                        />
                </ProForm>
           </ProCard>
        </Modal>
        </> ;
}

export default App;